"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var jsencrypt_1 = require("jsencrypt");
/** RSA数据加密 */
var YangJsEncrypt = /** @class */ (function () {
    function YangJsEncrypt(props) {
        this.publicKey = '';
        this.privateKey = '';
        this.publicKey = props.publicKey;
        this.privateKey = props.privateKey;
    }
    /** 公钥加密 */
    YangJsEncrypt.prototype.encryptPublicData = function (data) {
        var encrypt = new jsencrypt_1.default();
        encrypt.setPublicKey(this.publicKey);
        if (typeof data === 'object') {
            data = JSON.stringify(data);
        }
        return {
            passType: 'RSA',
            requestData: encrypt.encrypt(data)
        };
    };
    /** 私钥加密 */
    YangJsEncrypt.prototype.encryptPrivateData = function (data) {
        var encrypt = new jsencrypt_1.default();
        encrypt.setPublicKey(this.privateKey);
        if (typeof data === 'object') {
            data = JSON.stringify(data);
        }
        return {
            passType: 'RSA',
            requestData: encrypt.encrypt(data)
        };
    };
    /** 公钥解密 */
    YangJsEncrypt.prototype.decryptPublicData = function (data) {
        var decrypt = new jsencrypt_1.default();
        decrypt.setPublicKey(this.publicKey);
        if (typeof data === 'object') {
            data = JSON.stringify(data);
        }
        return JSON.parse(decrypt.decrypt(data) || '{}');
    };
    /** 私钥解密 */
    YangJsEncrypt.prototype.decryptPrivateData = function (data) {
        var decrypt = new jsencrypt_1.default();
        decrypt.setPublicKey(this.privateKey);
        if (typeof data === 'object') {
            data = JSON.stringify(data);
        }
        return JSON.parse(decrypt.decrypt(data) || '{}');
    };
    return YangJsEncrypt;
}());
exports.default = YangJsEncrypt;
